package Array;

import java.util.Arrays;

public class ArrayCenterIndex {

    /*
        date:2021/5/25 0:24
        leetcode：?
        问题:寻找数组两边相等的中间下标
     */

    public static int pivotIndex(int[] nums){

        int sum = Arrays.stream(nums).sum();
        System.out.println(sum);
        int total = 0;
        for (int i=0;i<nums.length;i++){
            total += nums[i];
            if (total == sum){
                return i;
            }
            sum = sum - nums[i];
        }

        return -1;
    }

    public static void main(String[] args) {
        int[] nums = {1,3,7,6,5,3};
        System.out.println(pivotIndex(nums));
    }
}
